//获取登录用户
import {getConfig, initDefaultUser, setConfig} from '@/mapper/config-store';

export async function login(opid, password) {
    const userList = await getConfig('user.list') || await initDefaultUser();
    return userList.find(u => u.opid === opid && u.password === password);
}

export async function getLastUser() {
    return await getConfig('user.lastUser') || 'admin';
}

export async function setLastUser(opid) {
    await setConfig('user.lastUser', opid);
    return 'ok'
}

export async function setCurrentUser(user) {
    await setConfig('user.currentUser', user);
    return 'ok'
}


export async function openConfigFile() {
    try {
        const {shell} = require('electron');
        const {app} = require('@electron/remote');
        const path = require('path')
        const configPath = path.join(app.getPath('userData'));
        await shell.openPath(configPath);
    } catch (e) {
        console.error('打开配置文件夹失败:', e);
    }
}